﻿using UnityEngine;
using System.Collections;

public class HeadToObject : MonoBehaviour {

	public GameObject targetObj;
	public float turnSpeed = 3.0f;
	// Use this for initialization
	void Start () {
		targetObj = GameObject.Find("Plane_Hero");
	}
	
	// Update is called once per frame
	void Update () {
		Vector3 moveDirection = targetObj.transform.position - transform.position;
		moveDirection.z = 0;
		moveDirection.Normalize();
		
		float targetAngle = Mathf.Atan2(moveDirection.y,moveDirection.x) *  Mathf.Rad2Deg + 90.0f;
		float slerpValue = turnSpeed * Time.deltaTime;
		transform.rotation = Quaternion.Slerp(transform.rotation, 
		                                      Quaternion.Euler( 0, 0, targetAngle ), 
		                                      slerpValue );
	}
}
